package edu.sctu.jarime.june.day20150618.knowHTTPClient;

import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user19 on 2015/6/19.
 */
public class KnowHttpClientDemo {
    public void usehttpurlconnection() throws Exception{
        //实例对象
        String p="code[name]=lili&code[password]=lili19960721";
        URL url = new URL(p);
        URLConnection urlConnection= url.openConnection();
        HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;

        //配置
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setDoInput(true);
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setRequestProperty("content-type","text/xml");
        httpURLConnection.setRequestMethod("post");
        httpURLConnection.connect();

        //写/发送数据
        OutputStream outputStream = httpURLConnection.getOutputStream();
        ObjectOutputStream objectoutputStream = new ObjectOutputStream(outputStream);
        objectoutputStream.write(p.getBytes());
        objectoutputStream.flush();
        objectoutputStream.close();
        InputStream inputStream = httpURLConnection.getInputStream();


    }

}
